<!--
(C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
All rights reserved. This program and the accompanying materials
are made available under the terms of the GNU Lesser General Public License
(LGPL) version 2.1 which accompanies this distribution, and is available at
http://www.gnu.org/licenses/lgpl.html
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Contributors:
  Nelson Silva <nsilva@nuxeo.com>
-->
<link rel="import" href="../nuxeo-chart-data-behavior/nuxeo-chart-data-behavior.html">
<dom-module id="nuxeo-repository-analytics-dashboard">

  <link rel="import" type="css" href="../dashboard.css">

  <template>

    <!-- Number of documents -->
    <nuxeo-repository-data start-date="[[startDate]]" end-date="[[endDate]]"
                           metrics="cardinality(ecm:uuid)" data="{{totalCount}}"
                           index="[[index]]">
    </nuxeo-repository-data>

    <paper-card heading="Documents" elevation="2">
      <div class="card-content">
        <iron-icon icon="icons:description"></iron-icon>
        <h1>[[totalCount]]</h1>
      </div>
    </paper-card>

    <!-- Document count per type -->
    <nuxeo-repository-data start-date="[[startDate]]" end-date="[[endDate]]"
                           grouped-by="ecm:primaryType"
                           group-limit="10"
                           data="{{typeCount}}"
                           index="[[index]]">
    </nuxeo-repository-data>

    <paper-card heading="Document Types" elevation="2">
      <div class="card-content">
        <chart-pie values="[[_values(typeCount)]]"
                   series="[[_series(typeCount)]]"
                   colors="[[colors]]"
                   options='{"responsive": true, "animation": false}'>
        </chart-pie>
      </div>
    </paper-card>

    <!-- Top 10 creators -->
    <nuxeo-repository-data start-date="[[startDate]]" end-date="[[endDate]]"
                           grouped-by="dc:creator"
                           group-limit="10"
                           data="{{topCreators}}"
                           index="[[index]]">
    </nuxeo-repository-data>

    <paper-card heading="Top 10 creators" elevation="2">
      <div class="card-content">
        <chart-pie values="[[_values(topCreators)]]"
                   series="[[_series(topCreators)]]"
                   colors="[[colors]]"
                   options='{"responsive": true, "animation": false}'>
        </chart-pie>
      </div>
    </paper-card>

    <!-- Documents created per week -->
    <nuxeo-repository-data start-date="[[startDate]]" end-date="[[endDate]]"
                           with-date-intervals="week"
                           date-field="dc:created"
                           data="{{docsCreatedPerWeek}}"
                           index="[[index]]">
    </nuxeo-repository-data>

    <paper-card heading="Document created" elevation="2">
      <div class="card-content">
        <chart-line labels="[[_labels(docsCreatedPerWeek)]]"
                    values="[[_values(docsCreatedPerWeek)]]"
                    options='{"responsive": true, "animation": false, "datasetFill": false}'>
        </chart-line>
      </div>
    </paper-card>

    <!-- Documents modified per week -->
    <nuxeo-repository-data start-date="[[startDate]]" end-date="[[endDate]]"
                           with-date-intervals="week"
                           date-field="dc:modified"
                           data="{{docsModifiedPerWeek}}"
                           index="[[index]]">
    </nuxeo-repository-data>

    <paper-card heading="Documents modified" elevation="2">
      <div class="card-content">
        <chart-line labels="[[_labels(docsModifiedPerWeek)]]"
                    values="[[_values(docsModifiedPerWeek)]]"
                    options='{"responsive": true, "animation": false, "datasetFill": false}'>
        </chart-line>
      </div>
    </paper-card>

  </template>

</dom-module>

<script>
  Polymer({
    is: 'nuxeo-repository-analytics-dashboard',
    behaviors: [Nuxeo.ChartDataBehavior],
    properties: {
      index: {
        type: String,
        value: 'nuxeo'
      },
      startDate: String,
      endDate: String,
      colors: {
        type: Array,
        value: ['#fb8072', '#8dd3c7', '#ffffb3', '#bebada', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd']
      }
    }
  });
</script>
